package kevin.framework.basic.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import kevin.framework.basic.dao.IBaseDao;
import kevin.framework.basic.dao.IDictDao;
import kevin.framework.basic.domain.Dict;
import kevin.framework.basic.service.IDictService;

/**
 * Generate by Kevin's CodeBuilder
 **/
@Service
public class DictService extends BaseService<Dict, String> implements IDictService {

    private static final long serialVersionUID = -1L;

    private IDictDao dictDao;

    @Resource(name = "dictDao")
    @Override
    public void setDao(IBaseDao<Dict, String> dao) {
        this.dao = dao;
        dictDao = (IDictDao)dao;
    }

    /***
     * 动态跨库 操作 local 库 remote 库 remote = 默认库
     ***/
    @Override
    public int insert(Dict entity) throws Exception {

        int r = super.insert(entity);
        return r;
    }

    @Override
    public int update(Dict entity) throws Exception {

        return super.update(entity);
    }

    @Override
    public int deleteBatch(List<String> list) throws Exception {

        return super.deleteBatch(list);
    }

    @Override
    public Long getvisitorCount() throws Exception {
        // TODO Auto-generated method stub
        Map<String, Object> prsMap = new HashMap<String, Object>();
        String typeid = "-111111";
        prsMap.put("typeid", typeid);
        List<Dict> listDicts = this.selectParam(prsMap);
        Dict dict;
        Long countLong = 1L;
        if (listDicts.size() > 0) {
            dict = listDicts.get(0);
            countLong = Long.valueOf(dict.getDvalue());
        }
        return countLong;
    }

    @Override
    public void visitorCount() throws Exception {
        // TODO Auto-generated method stub
        Map<String, Object> prsMap = new HashMap<String, Object>();
        String typeid = "-111111";
        prsMap.put("typeid", typeid);
        List<Dict> listDicts = this.selectParam(prsMap);
        Dict dict;
        if (listDicts.size() > 0) {
            dict = listDicts.get(0);
            Long count = Long.valueOf(dict.getDvalue()) + 1;
            dict.setDvalue(String.valueOf(count));
            this.update(dict);
        } else {
            dict = new Dict();
            dict.setDesp("网站访问统计");
            dict.setDkey("vistcount");
            dict.setTypeid(typeid);
            dict.setDvalue("1");
            this.insert(dict);
        }
    }

}
